package control;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.UpdateArticle;

@WebServlet("/AddArticle")
public class AddArticle extends HttpServlet {
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setContentType("text/plain;charset=utf-8");
		
		String addTitle = req.getParameter("addTitle");
		String addContent = req.getParameter("addContent");
		String addCategory = req.getParameter("addCategory");
		
		if (addTitle != null && addContent != null && addCategory != null) {
			UpdateArticle update = new UpdateArticle();
			boolean status = update.addContent(addTitle, addContent, addCategory);
			
			PrintWriter out = resp.getWriter();
			out.print(status);
			out.close();
		}else {
			PrintWriter out = resp.getWriter();
			out.print(false);
			out.close();
		}
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO 自动生成的方法存根
	}
}
